package com.tungse.juc.collection;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListTest {
    public static void main(String[] args) {
        //List<String> list = new ArrayList<>(); //并发下会报错
        //List<String> list = Collections.synchronizedList(new ArrayList<>());//并发下不会报错
        //List<String> list = new Vector<>();
        List<String> list = new CopyOnWriteArrayList<>();
        //Vector是线程安全的，但是效率低
        //CopyOnWriteArrayList是线程安全的，效率高

        for (int i = 0; i < 150; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(1,5));
                System.out.println(list);
            },i+"").start();
        }
    }
}
